<template>
  <div>
    <el-dialog title="部门管理" :visible.sync="dialogVisible" width="50%" center>

      <div>
        <el-form :model="form"  ref="ruleForm" label-width="80px">

          <el-row>
            <el-col :span="12">
            </el-col>
            <el-col :span="12">
              <el-form-item label="部门名称" >
                <el-input v-model="form.name" class="inputwidth"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitForm('ruleForm')" :loading="btnloading">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import {
    Message
  } from 'element-ui';
  import {
    mapState,
    mapMutations
  } from 'vuex';

  export default {
    data() {
      return {
        dialogVisible:false,
        form: {
           id: '',
        },
        btnloading:false
      }
    },
    created() {

    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            
            this.axios.post("/user/departmentEdit", this.form).then(res => {
               this.btnloading=true;
              Message.success({
                message: "成功",
                onClose: (res) => {
                  this.btnloading=false;
                  this.dialogVisible = false;
                  this.$emit('update');
                }
              })
            }).catch(error => {
this.btnloading=false;
            })
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },


    }
  }
</script>

<style>
  .el-cascader-menu {
    height: 200px;
  }
</style>
